using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;


/// <summary>
/// Summary description for processPaymentType
/// </summary>
public class processPaymentType:DBConnectionTool
{
	public processPaymentType():base()
	{
		//
		// TODO: Add constructor logic here
		//
	}

    public string getPaymentTypeID()
    {
        OpenCn();
        SqlCommand cmd = new SqlCommand("select right(max(PaymentTypeID),2) from PaymentTypes", cn);
        String s = cmd.ExecuteScalar().ToString();
        Int32 result;
        if (Int32.TryParse(s, out result))
            result++;
        else
            result = 1;
        int l = result.ToString().Length;
        int count = 2 - l;
        string sresult = "PaT";
        for (int i = 0; i < count; i++)
        {
            sresult = sresult + "0";
        }
        sresult = sresult + result;
        CloseCn();
        return sresult;
    }

    public DataTable getPaymentType()
    {
        OpenCn();
        SqlDataAdapter da = new SqlDataAdapter("Select * from PaymentTypes", cn);
        DataTable dt = new DataTable("PaymentTypes");
        da.Fill(dt);
        CloseCn();
        return dt;
    }

    public int insertPaymentType(string PaymentTypeID, string PaymentTypeName)
    {
        OpenCn();
        SqlCommand cmd = new SqlCommand("Insert Into PaymentTypes(PaymentTypeID,PaymentTypeName) Values(@PaymentTypeID,@PaymentTypeName)", cn);
        cmd.Parameters.Add(new SqlParameter("@PaymentTypeID", SqlDbType.Char, 5));
        cmd.Parameters.Add(new SqlParameter("@PaymentTypeName", SqlDbType.NVarChar, 200));        
        cmd.Parameters["@PaymentTypeID"].Value = PaymentTypeID;
        cmd.Parameters["@PaymentTypeName"].Value = PaymentTypeName;        
        int result = cmd.ExecuteNonQuery();
        CloseCn();
        return result;
    }
    public int updatePaymentType(string PaymentTypeID, string PaymentTypeName)
    {
        OpenCn();
        SqlCommand cmd = new SqlCommand("update PaymentTypes set PaymentTypeName=@PaymentTypeName where PaymentTypeID=@PaymentTypeID", cn);
        cmd.Parameters.Add(new SqlParameter("@PaymentTypeID", SqlDbType.Char, 5));
        cmd.Parameters.Add(new SqlParameter("@PaymentTypeName", SqlDbType.NVarChar, 200));
        cmd.Parameters["@PaymentTypeID"].Value = PaymentTypeID;
        cmd.Parameters["@PaymentTypeName"].Value = PaymentTypeName;
        int result = cmd.ExecuteNonQuery();
        CloseCn();
        return result;
    }

    public int deletePaymentType(string PaymentTypeID)
    {
        OpenCn();
        SqlCommand cmd = new SqlCommand("Delete PaymentTypes Where PaymentTypeID ='" + PaymentTypeID + "'", cn);
        int result = cmd.ExecuteNonQuery();
        CloseCn();
        return result;
    }
}
